/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.panpf.sketch.zoom;

import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

/**
 * PixmapBuild
 */
public class PixmapBuild {
    ImageSource imageSource;
    ImageSource.DecodingOptions decodingOptions;
    PixelMap pixelMap;

    public PixmapBuild(ImageSource imageSource) {
        this.imageSource = imageSource;
        if (imageSource != null) {
            pixelMap = imageSource.createPixelmap(null);
        }
    }

    public PixmapBuild(ImageSource imageSource, ImageSource.DecodingOptions decodingOptions) {
        this.imageSource = imageSource;
        if (imageSource != null) {
            pixelMap = imageSource.createPixelmap(decodingOptions);
        }

    }

    public ImageSource getImageSource() {
        return imageSource;
    }

    public PixmapBuild setImageSource(ImageSource imageSource) {
        this.imageSource = imageSource;
        return this;
    }

    public ImageSource.DecodingOptions getDecodingOptions() {
        return decodingOptions;
    }

    public PixmapBuild setDecodingOptions(ImageSource.DecodingOptions decodingOptions) {
        this.decodingOptions = decodingOptions;
        if (imageSource != null && !imageSource.isReleased()) {
            pixelMap = imageSource.createPixelmap(decodingOptions);
        }
        return this;
    }

    public PixelMap getPixelMap() {
        if (pixelMap == null && imageSource != null) {
            pixelMap = imageSource.createPixelmap(decodingOptions);
        }
        return pixelMap;
    }

    public PixmapBuild setPixelMap(PixelMap pixelMap) {
        this.pixelMap = pixelMap;
        return this;
    }
}
